#include<stdio.h>
main()
{
	int ThisSum, MaxSum;
	int i, N, count = 0;
  	ThisSum = MaxSum = 0;

  	scanf("%d",&N);
  	int A[N];
  	for(i = 0; i < N; i++)
	{
        scanf("%d", &A[i]);
  	}


  	for(i = 0; i < N; i++)
  	{
        ThisSum += A[i];

        if(ThisSum > MaxSum)
        {
          MaxSum = ThisSum;
        }
        else if ( ThisSum < 0 )
        {
          ThisSum = 0;
        }
  	}


    printf("%d",MaxSum);

    return 0;
}
